<?php

class PC4_Controlador_Crud_Perfil extends PC4_Controlador_Crud_Usuarios
{

	public $campoLogin;
	
	function init() {
		parent::init();
		
		$auth = Zend_Auth::getInstance();
		$usuario = $auth->getIdentity();
		$this->campoLogin = 'usuario';
		$this->campoSenha = 'senha';
        $this->nomeSecao = 'Alterar dados';
		
		$this->appendPastaView('usuarios');
		
		$this->_setParam('id', $usuario->id);
	}
	
	function indexAction() {
		$this->_forward('form');
	}
	
	protected function getBean($id = 0) {
		$bean = parent::getBean($id);
		if (isset($bean[$this->campoSenha]) && $bean[$this->campoSenha] == md5('')) {
			unset($bean[$this->campoSenha]);
		}
		return $bean;
	}
	
	protected function persisteEdita($registro, $id) {
		$campoSenha = $this->campoSenha;
		parent::persisteEdita($registro, $id);
		if (empty($registro[$campoSenha])) {
			$this->veAction();
			$registro[$this->campoSenha] = $this->view->r->$campoSenha;
		}
		$this->_forward('entra', 'login', 'admin', array(
			$this->campoLogin => $registro[$this->campoLogin],
			$this->campoSenha => $registro[$this->campoSenha],
			'naoTrataSenha' => 'sim'
		));
	}
	
}
